package com.xiaoxin.controller;

import com.xiaoxin.common.recketMq.template.RocketMQEnhanceTemplate;
import com.xiaoxin.mq.consumer.message.MemberMessage;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.apache.rocketmq.spring.support.RocketMQHeaders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.UUID;

/**
 * @author: EDY
 * @createTime: 2024-09-02 10:18
 **/
@Tag(name = "测试MQ")
@RestController
@RequestMapping("enhance")
@Slf4j
public class EnhanceProduceController {

    @Autowired
    private RocketMQEnhanceTemplate rocketMQEnhanceTemplate;

    private static final String topic = "ROCKET_ENHANCE";
    private static final String tag = "MEMBER";

    @Autowired
    private  RocketMQTemplate template;
    /**
     * 发送实体消息
     */
    @GetMapping("/member")
    public SendResult member() {
        String key = UUID.randomUUID().toString();
        MemberMessage message = new MemberMessage();
        // 设置业务key
        message.setKey(key);
        // 设置消息来源，便于查询
        message.setSource("MEMBER");
        // 业务消息内容
        message.setUserName("Java日知录");
        message.setBirthday(LocalDateTime.now());

        return rocketMQEnhanceTemplate.send(topic, tag, message);
    }

/*    @GetMapping("/member")
    public SendResult member() {
        String key = UUID.randomUUID().toString();
        MemberMessage message = new MemberMessage();
        // 设置业务key
        message.setKey(key);
        // 设置消息来源，便于查询
        message.setSource("MEMBER");
        // 业务消息内容
        message.setUserName("Java日知录");
        message.setBirthday(LocalDateTime.now());
        Message<MemberMessage> sendMessage = MessageBuilder.withPayload(message).setHeader(RocketMQHeaders.KEYS, message.getKey()).build();
        return template.syncSend("staff-consumer", sendMessage);
    }*/
}

